﻿@{
    ViewBag.Title = "AlterOrderList";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        $("#ProjectID").combobox({
            editable: false, panelHeight: "auto",
            valueField: 'ID',
            textField: 'ProjectName',
            url: '/ProjectInfo/ProjectInfoListForFlow',
            onLoadSuccess: function () {
                var data = $("#ProjectID").combobox('getData');
                if (data.length > 0) {
                    $("#ProjectID").combobox('select', data[0]["ID"]);
                }
            },
            onSelect: function (record) {
                initContract(record.ID);
            }
        });
    });

    function initContract(projectID) {
        $("#ContractID").combobox({
            editable: false, panelHeight: "auto",
            valueField: 'ID',
            textField: 'ContractName',
            url: '/ContractInfo/ContractInfoListByProjectIDAndType?projectID=' + projectID + '&contractType=' + encodeURI("施工合同"),
            onLoadSuccess: function () {
                var data = $("#ContractID").combobox('getData');
                if (data.length > 0) {
                    $("#ContractID").combobox('select', data[0]["ID"]);
                }
            },
            onSelect: function (record) {
                initTable();
            }
        });
    }

    function initTable() {
        var projectID = $("#ProjectID").combobox('getValue');
        var contractID = $("#ContractID").combobox('getValue');
        $('#myDataGrid').datagrid({
            url: '/AlterOrder/GetAlterOrderList?projectID=' + projectID + '&contractID=' + contractID,//一个用以从远程站点请求数据的超链接地址
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: false,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            pagination: true,
            pageSize: 20,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',//表明该列是一个唯一列。
            singleSelect: true,
            fitColumns: true,
            sortName: 'AlterOrderName',
            columns: [[
                        { title: 'AlterOrderID', field: 'AlterOrderID', hidden: true },
                        { title: 'FlowCode', field: 'FlowCode', hidden: true },
                        { title: 'HandleState', field: 'HandleState', hidden: true },
                        {
                            title: '变更令名称', field: 'AlterOrderName', width: 240,
                            formatter:
                            function (value, row, index) {
                                return '<a href="#" onclick=PopAlterOrder("' + row.HandleState + '","' + row.FlowCode + '","' + row.AlterOrderID + '")>' + row.AlterOrderName + '</a>';
                            }
                        },
                        { title: '变更令编码', field: 'AlterOrderCode', width: 70, sortable: true },
                        { title: '变更类型', field: 'AlterType', width: 70, sortable: true },
                        { title: '批复日期', field: 'RequestDate', width: 120, sortable: true, formatter: function (value, rec) { if (value) { return dateConvert(value); } } },
                        { title: '批复金额（元）', field: 'AlterMoney', width: 100, sortable: true },
                        { title: '增减工期（天）', field: 'AlterDate', width: 100, sortable: true },
                        //{ title: '已完成金额（元）', field: '', width: 100, sortable: true },
                        //{ title: '完成百分比', field: '', width: 100, sortable: true },
            ]],
            toolbar: '#myToolBar',
            onDblClickRow: function (rowIndex, rowData) {
                PopAlterOrder(rowData.HandleState, rowData.FlowCode, rowData.AlterOrderID);
            }
        });
    }

    function PopAlterOrder(handleState, flowCode, id) {
        var processType = '1';
        if (handleState == "0") {
            processType = '2';
        }
        showMyWindow("#alterOrderListWindow", "", "/AlterOrder/AlterOrder?MenuCode=AlterOrder&sourceType=0&processType=" + processType + "&sourceID=&alterOrderID=" + id, 1000, 500, true, true, true);
    }

    function PopAddAlterOrder(department) {
        showMyWindow("#alterOrderListWindow", "", "/AlterOrder/AlterOrder?MenuCode=AlterOrder&sourceType=1&processType=&sourceID=&lastUpdateUserDepartment=" + department, 1000, 500, true, true, true);
    }

    var AlterOrderList =
    {
        AddAlterOrder: function () {
            $.post("/UserMenuAction/GetUserDepartmentForFlow?menuCode=AlterOrderList", function (userDepartment) {
                if (userDepartment == "") {
                    showMyWindow("#alterOrderListWindow", "选择机构", "/UserMenuAction/ShowOrgByUserForFlow?menuCode=AlterOrderList", 500, 280, true, false);
                }
                else if (userDepartment == "**********") {
                    $.messager.alert('操作提示', '当前用户不属于任何机构，请先设置所属机构！', 'info');
                }
                else if (userDepartment == "++++++++++") {
                    $.messager.alert('操作提示', '当前用户的机构不属于流程申请配置机构，不能新增！', 'info');
                }
                else {
                    PopAddAlterOrder(userDepartment);
                }
            });
            //$.post("/UserMenuAction/GetUserDepartment?menuCode=AlterOrderList&actionCode=AddAlterOrder", function (userDepartment) {
            //    if (userDepartment == "") {
            //        showMyWindow("#alterOrderListWindow", "选择机构", "/UserMenuAction/ShowOrgByUser?menuCode=AlterOrderList&actionCode=AddAlterOrder", 500, 280, true, false);
            //    }
            //    else if (userDepartment == "**********") {
            //        $.messager.alert('操作提示', '当前用户不属于任何机构，请先设置所属机构！', 'info');
            //    }
            //    else {
            //        PopAddAlterOrder(userDepartment);
            //    }
            //});
        },

        DeleteAlterOrder: function () {
            var selectAlter = $('#myDataGrid').datagrid('getSelections');
            if (selectAlter == "[]") {
                $.messager.alert('操作提示', '请选择要删除的行！', 'info');
            }
            else {
                $.messager.confirm('操作提示', "确认删除[ " + selectAlter[0].AlterOrderName + " ]吗？", function (r) {
                    if (r) {
                        $.post("/AlterOrder/DeleteSelectAlterOrder?AlterOrderID=" + selectAlter[0].AlterOrderID, function (res) {
                            if (res == "Success") {
                                //移除删除的数据
                                $("#myDataGrid").datagrid("reload");
                                $("#myDataGrid").datagrid("clearSelections");
                                $.messager.alert('操作提示', '删除成功!', 'info');
                            }
                            else {
                                if (res == "") {
                                    $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                                }
                                else {
                                    $.messager.alert('操作提示', res, 'info');
                                }
                            }
                        });
                    }
                });
            }
        }
    }

    function cancelPopWindow(handleState) {
        if (handleState == "0") {
            initTable();
        }
        colseMyWindow("#alterOrderListWindow");
    }

    function CloseWindow(data) {
        colseMyWindow("#alterOrderListWindow");
        initTable();
        $.EasyuiSlide(data);
    }
</script>
<div class="easyui-layout" fit="true">
    <div data-options="region:'north'" style="height:35px;">
        <table style="margin-top: 5px">
            <tr id="trCommon">
                <td style="width: 95px; text-align: center">项目名称</td>
                <td>
                    <input id="ProjectID" name="ProjectID" class="easyui-combobox" style="width: 180px;" />
                </td>
                <td style="width: 95px; text-align: center">标段名称</td>
                <td>
                    <input id="ContractID" name="ContractID" class="easyui-combobox" style="width: 180px;" />
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center'">
        <table id="myDataGrid" fit="true"></table>
        <div id="myToolBar">@Html.Raw(ViewBag.ToolBarInfo)</div>
        <div id="alterOrderListWindow"></div>
    </div>
</div>
